home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / drivers / gaiden.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  26KB  |  699 lines

  1. /***************************************************************************
  2.  
  3. Ninja Gaiden memory map (preliminary)
  4.  
  5. 000000-03ffff ROM
  6. 060000-063fff RAM
  7. 070000-070fff Video RAM (text layer)
  8. 072000-075fff VRAM (backgrounds)
  9. 076000-077fff Sprite RAM
  10. 078000-079fff Palette RAM
  11.  
  12. 07a100-07a1ff Unknown
  13.  
  14. memory mapped ports:
  15.  
  16. read:
  17. 07a001    IN0
  18. 07a002    IN2
  19. 07a003    IN1
  20. 07a004    DWSB
  21. 07a005    DSWA
  22. see the input_ports definition below for details on the input bits
  23.  
  24. write:
  25. 07a104-07a105 text layer Y scroll
  26. 07a10c-07a10d text layer X scroll
  27. 07a204-07a205 front layer Y scroll
  28. 07a20c-07a20d front layer X scroll
  29. 07a304-07a305 back layer Y scroll
  30. 07a30c-07a30d back layer Xscroll
  31.  
  32. ***************************************************************************/
  33.  
  34. #include "driver.h"
  35. #include "vidhrdw/generic.h"
  36. #include "cpu/m68000/m68000.h"
  37. #include "cpu/z80/z80.h"
  38.  
  39. extern unsigned char *gaiden_videoram;
  40. extern unsigned char *gaiden_videoram2;
  41. extern unsigned char *gaiden_videoram3;
  42.  
  43. void gaiden_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  44.  
  45. WRITE_HANDLER( gaiden_unknownram_w );
  46. READ_HANDLER( gaiden_unknownram_r );
  47. WRITE_HANDLER( gaiden_videoram_w );
  48. READ_HANDLER( gaiden_videoram_r );
  49. WRITE_HANDLER( gaiden_videoram2_w );
  50. READ_HANDLER( gaiden_videoram2_r );
  51. WRITE_HANDLER( gaiden_videoram3_w );
  52. READ_HANDLER( gaiden_videoram3_r );
  53.  
  54. WRITE_HANDLER( gaiden_txscrollx_w );
  55. WRITE_HANDLER( gaiden_txscrolly_w );
  56. WRITE_HANDLER( gaiden_fgscrollx_w );
  57. WRITE_HANDLER( gaiden_fgscrolly_w );
  58. WRITE_HANDLER( gaiden_bgscrollx_w );
  59. WRITE_HANDLER( gaiden_bgscrolly_w );
  60.  
  61.  
  62. WRITE_HANDLER( gaiden_background_w );
  63. void gaiden_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  64.  
  65. int  gaiden_vh_start(void);
  66.  
  67.  
  68. int gaiden_interrupt(void)
  69. {
  70.     return 5;  /*Interrupt vector 5*/
  71. }
  72.  
  73. READ_HANDLER( gaiden_input_r )
  74. {
  75.     switch (offset)
  76.     {
  77.         case 0:
  78.             return input_port_4_r (offset);
  79.             break;
  80.         case 2:
  81.             return (input_port_1_r (offset) << 8) + (input_port_0_r (offset));
  82.             break;
  83.         case 4:
  84.             return (input_port_3_r (offset) << 8) + (input_port_2_r (offset));
  85.             break;
  86.     }
  87.  
  88.     return 0;
  89. }
  90.  
  91.  
  92. WRITE_HANDLER( gaiden_sound_command_w )
  93. {
  94.     if (data & 0xff000000) soundlatch_w(0,data & 0xff);    /* Ninja Gaiden */
  95.     if (data & 0x00ff0000) soundlatch_w(0,(data >> 8) & 0xff);    /* Tecmo Knight */
  96.     cpu_cause_interrupt(1,Z80_NMI_INT);
  97. }
  98.  
  99.  
  100.  
  101. /* Tecmo Knight has a simple protection. It writes codes to 0x07a804, and reads */
  102. /* the answer from 0x07a007. The returned values contain the address of a */
  103. /* function to jump to. */
  104.  
  105. static int prot;
  106.  
  107. WRITE_HANDLER( tknight_protection_w )
  108. {
  109.     static int jumpcode;
  110.     static int jumppoints[] =
  111.     {
  112.         0x0c0c,0x0cac,0x0d42,0x0da2,0x0eea,0x112e,0x1300,0x13fa,
  113.         0x159a,0x1630,0x109a,0x1700,0x1750,0x1806,0x18d6,0x1a44,
  114.         0x1b52
  115.     };
  116.  
  117.     data = (data >> 8) & 0xff;
  118.  
  119. //logerror("PC %06x: prot = %02x\n",cpu_get_pc(),data);
  120.  
  121.     switch (data & 0xf0)
  122.     {
  123.         case 0x00:    /* init */
  124.             prot = 0x00;
  125.             break;
  126.         case 0x10:    /* high 4 bits of jump code */
  127.             jumpcode = (data & 0x0f) << 4;
  128.             prot = 0x10;
  129.             break;
  130.         case 0x20:    /* low 4 bits of jump code */
  131.             jumpcode |= data & 0x0f;
  132.             if (jumpcode > 16)
  133.             {
  134. logerror("unknown jumpcode %02x\n",jumpcode);
  135.                 jumpcode = 0;
  136.             }
  137.             prot = 0x20;
  138.             break;
  139.         case 0x30:    /* ask for bits 12-15 of function address */
  140.             prot = 0x40 | ((jumppoints[jumpcode] >> 12) & 0x0f);
  141.             break;
  142.         case 0x40:    /* ask for bits 8-11 of function address */
  143.             prot = 0x50 | ((jumppoints[jumpcode] >> 8) & 0x0f);
  144.             break;
  145.         case 0x50:    /* ask for bits 4-7 of function address */
  146.             prot = 0x60 | ((jumppoints[jumpcode] >> 4) & 0x0f);
  147.             break;
  148.         case 0x60:    /* ask for bits 0-3 of function address */
  149.             prot = 0x70 | ((jumppoints[jumpcode] >> 0) & 0x0f);
  150.             break;
  151.     }
  152. }
  153.  
  154. READ_HANDLER( tknight_protection_r )
  155. {
  156. //logerror("PC %06x: read prot %02x\n",cpu_get_pc(),prot);
  157.     return prot;
  158. }
  159.  
  160.  
  161.  
  162. static struct MemoryReadAddress readmem[] =
  163. {
  164.     { 0x000000, 0x03ffff, MRA_ROM },
  165.     { 0x060000, 0x063fff, MRA_BANK1 },   /* RAM */
  166.     { 0x070000, 0x070fff, gaiden_videoram_r },
  167.     { 0x072000, 0x073fff, gaiden_videoram2_r },
  168.     { 0x074000, 0x075fff, gaiden_videoram3_r },
  169.     { 0x076000, 0x077fff, MRA_BANK2 },
  170.     { 0x078000, 0x0787ff, paletteram_word_r },
  171.     { 0x078800, 0x079fff, MRA_NOP },   /* extra portion of palette RAM, not really used */
  172.     { 0x07a000, 0x07a005, gaiden_input_r },
  173.     { 0x07a006, 0x07a007, tknight_protection_r },
  174.     { -1 }  /* end of table */
  175. };
  176.  
  177. static struct MemoryWriteAddress writemem[] =
  178. {
  179.     { 0x000000, 0x03ffff, MWA_ROM },
  180.     { 0x060000, 0x063fff, MWA_BANK1 },
  181.     { 0x070000, 0x070fff, gaiden_videoram_w, &gaiden_videoram },
  182.     { 0x072000, 0x073fff, gaiden_videoram2_w,  &gaiden_videoram2 },
  183.     { 0x074000, 0x075fff, gaiden_videoram3_w,  &gaiden_videoram3 },
  184.     { 0x076000, 0x077fff, MWA_BANK2, &spriteram },
  185.     { 0x078000, 0x0787ff, paletteram_xxxxBBBBGGGGRRRR_word_w, &paletteram },
  186.     { 0x078800, 0x079fff, MWA_NOP },   /* extra portion of palette RAM, not really used */
  187.     { 0x07a104, 0x07a105, gaiden_txscrolly_w },
  188.     { 0x07a10c, 0x07a10d, gaiden_txscrollx_w },
  189.     { 0x07a204, 0x07a205, gaiden_fgscrolly_w },
  190.     { 0x07a20c, 0x07a20d, gaiden_fgscrollx_w },
  191.     { 0x07a304, 0x07a305, gaiden_bgscrolly_w },
  192.     { 0x07a30c, 0x07a30d, gaiden_bgscrollx_w },
  193.     { 0x07a800, 0x07a801, MWA_NOP },
  194.     { 0x07a802, 0x07a803, gaiden_sound_command_w },
  195.     { 0x07a804, 0x07a805, tknight_protection_w },
  196.     { 0x07a806, 0x07a807, MWA_NOP },
  197.     { -1 }  /* end of table */
  198. };
  199.  
  200. static struct MemoryReadAddress sound_readmem[] =
  201. {
  202.     { 0x0000, 0xdfff, MRA_ROM },
  203.     { 0xf000, 0xf7ff, MRA_RAM },
  204.     { 0xf800, 0xf800, OKIM6295_status_0_r },
  205.     { 0xfc00, 0xfc00, MRA_NOP },    /* ?? */
  206.     { 0xfc20, 0xfc20, soundlatch_r },
  207.     { -1 }    /* end of table */
  208. };
  209.  
  210. static struct MemoryWriteAddress sound_writemem[] =
  211. {
  212.     { 0x0000, 0xdfff, MWA_ROM },
  213.     { 0xf000, 0xf7ff, MWA_RAM },
  214.     { 0xf800, 0xf800, OKIM6295_data_0_w },
  215.     { 0xf810, 0xf810, YM2203_control_port_0_w },
  216.     { 0xf811, 0xf811, YM2203_write_port_0_w },
  217.     { 0xf820, 0xf820, YM2203_control_port_1_w },
  218.     { 0xf821, 0xf821, YM2203_write_port_1_w },
  219.     { 0xfc00, 0xfc00, MWA_NOP },    /* ?? */
  220.     { -1 }    /* end of table */
  221. };
  222.  
  223.  
  224.  
  225. INPUT_PORTS_START( gaiden )
  226.     PORT_START      /* PLAYER 1 */
  227.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT | IPF_PLAYER1 | IPF_8WAY )
  228.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_PLAYER1 | IPF_8WAY )
  229.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN | IPF_PLAYER1 | IPF_8WAY )
  230.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP | IPF_PLAYER1 | IPF_8WAY )
  231.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON3 | IPF_PLAYER1 )
  232.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER1 )
  233.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER1 )
  234.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
  235.  
  236.     PORT_START      /* PLAYER 2 */
  237.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT | IPF_PLAYER2 | IPF_8WAY )
  238.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_PLAYER2 | IPF_8WAY )
  239.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN | IPF_PLAYER2 | IPF_8WAY )
  240.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP | IPF_PLAYER2 | IPF_8WAY )
  241.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON3 | IPF_PLAYER2 )
  242.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER2 )
  243.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER2 )
  244.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
  245.  
  246.     PORT_START    /* DSWA */
  247.     PORT_DIPNAME( 0x01, 0x01, DEF_STR( Demo_Sounds ) )
  248.     PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
  249.     PORT_DIPSETTING(    0x01, DEF_STR( On ) )
  250.     PORT_DIPNAME( 0x02, 0x02, DEF_STR( Flip_Screen ) )
  251.     PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
  252.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  253.     PORT_DIPNAME( 0x1c, 0x1c, DEF_STR( Coin_B ) )
  254.     PORT_DIPSETTING(    0x00, DEF_STR( 5C_1C ) )
  255.     PORT_DIPSETTING(    0x10, DEF_STR( 4C_1C ) )
  256.     PORT_DIPSETTING(    0x08, DEF_STR( 3C_1C ) )
  257.     PORT_DIPSETTING(    0x04, DEF_STR( 2C_1C ) )
  258.     PORT_DIPSETTING(    0x1c, DEF_STR( 1C_1C ) )
  259.     PORT_DIPSETTING(    0x0c, DEF_STR( 1C_2C ) )
  260.     PORT_DIPSETTING(    0x14, DEF_STR( 1C_3C ) )
  261.     PORT_DIPSETTING(    0x18, DEF_STR( 1C_4C ) )
  262.     PORT_DIPNAME( 0xe0, 0xe0, DEF_STR( Coin_A ) )
  263.     PORT_DIPSETTING(    0x00, DEF_STR( 5C_1C ) )
  264.     PORT_DIPSETTING(    0x80, DEF_STR( 4C_1C ) )
  265.     PORT_DIPSETTING(    0x40, DEF_STR( 3C_1C ) )
  266.     PORT_DIPSETTING(    0x20, DEF_STR( 2C_1C ) )
  267.     PORT_DIPSETTING(    0xe0, DEF_STR( 1C_1C ) )
  268.     PORT_DIPSETTING(    0x60, DEF_STR( 1C_2C ) )
  269.     PORT_DIPSETTING(    0xa0, DEF_STR( 1C_3C ) )
  270.     PORT_DIPSETTING(    0xc0, DEF_STR( 1C_4C ) )
  271.  
  272.     PORT_START    /* DSWB */
  273.     PORT_DIPNAME( 0x01, 0x01, DEF_STR( Unknown ) )
  274.     PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
  275.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  276.     PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
  277.     PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
  278.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  279.     PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
  280.     PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
  281.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  282.     PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
  283.     PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
  284.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  285.     PORT_DIPNAME( 0x30, 0x30, "Energy" )
  286.     PORT_DIPSETTING(    0x00, "2" )
  287.     PORT_DIPSETTING(    0x30, "3" )
  288.     PORT_DIPSETTING(    0x10, "4" )
  289.     PORT_DIPSETTING(    0x20, "5" )
  290.     PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Lives ) )
  291.     PORT_DIPSETTING(    0x00, "1" )
  292.     PORT_DIPSETTING(    0xc0, "2" )
  293.     PORT_DIPSETTING(    0x40, "3" )
  294.     PORT_DIPSETTING(    0x80, "4" )
  295.  
  296.     PORT_START    /* IN0 */
  297.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_START1 )
  298.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_START2 )
  299.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )
  300.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )
  301.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
  302.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
  303.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN1 )
  304.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN2 )
  305. INPUT_PORTS_END
  306.  
  307. INPUT_PORTS_START( tknight )
  308.     PORT_START      /* PLAYER 1 */
  309.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT | IPF_PLAYER1 | IPF_8WAY )
  310.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_PLAYER1 | IPF_8WAY )
  311.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN | IPF_PLAYER1 | IPF_8WAY )
  312.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP | IPF_PLAYER1 | IPF_8WAY )
  313.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER1 )
  314.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER1 )
  315.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON3 | IPF_PLAYER1 )
  316.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
  317.  
  318.     PORT_START      /* PLAYER 2 */
  319.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT | IPF_PLAYER2 | IPF_8WAY )
  320.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_PLAYER2 | IPF_8WAY )
  321.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN | IPF_PLAYER2 | IPF_8WAY )
  322.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP | IPF_PLAYER2 | IPF_8WAY )
  323.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER2 )
  324.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER2 )
  325.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON3 | IPF_PLAYER2 )
  326.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
  327.  
  328.     PORT_START    /* DSWA */
  329.     PORT_DIPNAME( 0xe0, 0xe0, DEF_STR( Coin_A ) )
  330.     PORT_DIPSETTING(    0x00, DEF_STR( 5C_1C ) )
  331.     PORT_DIPSETTING(    0x80, DEF_STR( 4C_1C ) )
  332.     PORT_DIPSETTING(    0x40, DEF_STR( 3C_1C ) )
  333.     PORT_DIPSETTING(    0x20, DEF_STR( 2C_1C ) )
  334.     PORT_DIPSETTING(    0xe0, DEF_STR( 1C_1C ) )
  335.     PORT_DIPSETTING(    0x60, DEF_STR( 1C_2C ) )
  336.     PORT_DIPSETTING(    0xa0, DEF_STR( 1C_3C ) )
  337.     PORT_DIPSETTING(    0xc0, DEF_STR( 1C_4C ) )
  338.     PORT_DIPNAME( 0x1c, 0x1c, DEF_STR( Coin_B ) )
  339.     PORT_DIPSETTING(    0x00, DEF_STR( 5C_1C ) )
  340.     PORT_DIPSETTING(    0x10, DEF_STR( 4C_1C ) )
  341.     PORT_DIPSETTING(    0x08, DEF_STR( 3C_1C ) )
  342.     PORT_DIPSETTING(    0x04, DEF_STR( 2C_1C ) )
  343.     PORT_DIPSETTING(    0x1c, DEF_STR( 1C_1C ) )
  344.     PORT_DIPSETTING(    0x0c, DEF_STR( 1C_2C ) )
  345.     PORT_DIPSETTING(    0x14, DEF_STR( 1C_3C ) )
  346.     PORT_DIPSETTING(    0x18, DEF_STR( 1C_4C ) )
  347.     PORT_DIPNAME( 0x02, 0x02, DEF_STR( Flip_Screen ) )
  348.     PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
  349.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  350.     PORT_DIPNAME( 0x01, 0x01, DEF_STR( Demo_Sounds ) )
  351.     PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
  352.     PORT_DIPSETTING(    0x01, DEF_STR( On ) )
  353.  
  354.     PORT_START    /* DSWB */
  355.     PORT_DIPNAME( 0x01, 0x01, DEF_STR( Unknown ) )
  356.     PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
  357.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  358.     PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
  359.     PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
  360.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  361.     PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
  362.     PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
  363.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  364.     PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
  365.     PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
  366.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  367.     PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
  368.     PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
  369.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  370.     PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
  371.     PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
  372.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  373.     PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Lives ) )
  374.     PORT_DIPSETTING(    0x80, "1" )
  375.     PORT_DIPSETTING(    0xc0, "2" )
  376.     PORT_DIPSETTING(    0x40, "3" )
  377. /*    PORT_DIPSETTING(    0x00, "2" ) */
  378.  
  379.     PORT_START    /* IN0 */
  380.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_START1 )
  381.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_START2 )
  382.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )
  383.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )
  384.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
  385.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
  386.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN1 )
  387.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN2 )
  388. INPUT_PORTS_END
  389.  
  390.  
  391.  
  392. static struct GfxLayout tilelayout =
  393. {
  394.     8,8,    /* tile size */
  395.     RGN_FRAC(1,1),    /* number of tiles */
  396.     4,    /* 4 bits per pixel */
  397.     { 0, 1, 2, 3 },
  398.     { 0*4, 1*4, 2*4, 3*4, 4*4, 5*4, 6*4, 7*4 },
  399.     { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32 },
  400.     32*8    /* offset to next tile */
  401. };
  402.  
  403. static struct GfxLayout tile2layout =
  404. {
  405.     16,16,    /* tile size */
  406.     RGN_FRAC(1,1),    /* number of tiles */
  407.     4,    /* 4 bits per pixel */
  408.     { 0, 1, 2, 3 },    /* the bitplanes are packed in one nibble */
  409.     { 0*4, 1*4, 2*4, 3*4, 4*4, 5*4, 6*4, 7*4,
  410.       32*8+0*4, 32*8+1*4, 32*8+2*4, 32*8+3*4,
  411.       32*8+4*4, 32*8+5*4, 32*8+6*4, 32*8+7*4,},
  412.     { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32,
  413.       16*32, 17*32, 18*32, 19*32, 20*32, 21*32, 22*32, 23*32},
  414.     128*8    /* offset to next tile */
  415. };
  416.  
  417. static struct GfxLayout spritelayout =
  418. {
  419.     8,8,    /* sprites size */
  420.     RGN_FRAC(1,2),    /* number of sprites */
  421.     4,    /* 4 bits per pixel */
  422.     { 0, 1, 2, 3 },    /* the bitplanes are packed in one nibble */
  423.     { 0,4,RGN_FRAC(1,2),4+RGN_FRAC(1,2),8,12,8+RGN_FRAC(1,2),12+RGN_FRAC(1,2) },
  424.     { 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16 },
  425.     16*8    /* offset to next sprite */
  426. };
  427.  
  428. static struct GfxDecodeInfo gfxdecodeinfo[] =
  429. {
  430.     { REGION_GFX1, 0, &tilelayout,        256, 16 },    /* tiles 8x8 */
  431.     { REGION_GFX2, 0, &tile2layout,       768, 16 },    /* tiles 16x16 */
  432.     { REGION_GFX3, 0, &tile2layout,       512, 16 },    /* tiles 16x16 */
  433.     { REGION_GFX4, 0, &spritelayout,        0, 16 },    /* sprites 8x8 */
  434.     { -1 } /* end of array */
  435. };
  436.  
  437.  
  438.  
  439. /* handler called by the 2203 emulator when the internal timers cause an IRQ */
  440. static void irqhandler(int irq)
  441. {
  442.     cpu_set_irq_line(1,0,irq ? ASSERT_LINE : CLEAR_LINE);
  443. }
  444.  
  445. static struct YM2203interface ym2203_interface =
  446. {
  447.     2,            /* 2 chips */
  448.     4000000,    /* 4 MHz ? (hand tuned) */
  449.     { YM2203_VOL(60,15), YM2203_VOL(60,15) },
  450.     { 0 },
  451.     { 0 },
  452.     { 0 },
  453.     { 0 },
  454.     { irqhandler }
  455. };
  456.  
  457.  
  458. static struct OKIM6295interface okim6295_interface =
  459. {
  460.     1,                  /* 1 chip */
  461.     { 7576 },            /* 7576Hz frequency */
  462.     { REGION_SOUND1 },    /* memory region */
  463.     { 20 }
  464. };
  465.  
  466.  
  467. static struct MachineDriver machine_driver_gaiden =
  468. {
  469.     /* basic machine hardware */
  470.     {
  471.         {
  472.             CPU_M68000,
  473.             8000000,    /* 8 Mhz */
  474.             readmem,writemem,0,0,
  475.             gaiden_interrupt,1,0,0
  476.         },
  477.         {
  478.             CPU_Z80 | CPU_AUDIO_CPU,
  479.             4000000,    /* 4 MHz */
  480.             sound_readmem,sound_writemem,0,0,
  481.             ignore_interrupt,0    /* NMIs are triggered by the main CPU */
  482.                                 /* IRQs are triggered by the YM2203 */
  483.         }
  484.     },
  485.     60, DEFAULT_60HZ_VBLANK_DURATION,
  486.     1,    /* 1 CPU slice per frame - interleaving is forced when a sound command is written */
  487.     0,
  488.  
  489.     /* video hardware */
  490.     32*8, 30*8, { 0*8, 32*8-1, 2*8, 30*8-1 },
  491.     gfxdecodeinfo,
  492.     1024, 1024,
  493.     0,
  494.  
  495.     VIDEO_TYPE_RASTER | VIDEO_MODIFIES_PALETTE,
  496.     0,
  497.     gaiden_vh_start,
  498.     0,
  499.     gaiden_vh_screenrefresh,
  500.  
  501.     /* sound hardware */
  502.     0,0,0,0,
  503.     {
  504.         {
  505.             SOUND_YM2203,
  506.             &ym2203_interface
  507.         },
  508.         {
  509.             SOUND_OKIM6295,
  510.             &okim6295_interface
  511.         }
  512.     }
  513. };
  514.  
  515.  
  516.  
  517. /***************************************************************************
  518.  
  519.   Game driver(s)
  520.  
  521. ***************************************************************************/
  522.  
  523. ROM_START( gaiden )
  524.     ROM_REGION( 0x40000, REGION_CPU1 )    /* 2*128k for 68000 code */
  525.     ROM_LOAD_EVEN( "gaiden.1",     0x00000, 0x20000, 0xe037ff7c )
  526.     ROM_LOAD_ODD ( "gaiden.2",     0x00000, 0x20000, 0x454f7314 )
  527.  
  528.     ROM_REGION( 0x10000, REGION_CPU2 )    /* 64k for the audio CPU */
  529.     ROM_LOAD( "gaiden.3",     0x0000, 0x10000, 0x75fd3e6a )   /* Audio CPU is a Z80  */
  530.  
  531.     ROM_REGION( 0x010000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  532.     ROM_LOAD( "gaiden.5",     0x000000, 0x10000, 0x8d4035f7 )    /* 8x8 tiles */
  533.  
  534.     ROM_REGION( 0x080000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  535.     ROM_LOAD( "14.bin",       0x000000, 0x20000, 0x1ecfddaa )
  536.     ROM_LOAD( "15.bin",       0x020000, 0x20000, 0x1291a696 )
  537.     ROM_LOAD( "16.bin",       0x040000, 0x20000, 0x140b47ca )
  538.     ROM_LOAD( "17.bin",       0x060000, 0x20000, 0x7638cccb )
  539.  
  540.     ROM_REGION( 0x080000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  541.     ROM_LOAD( "18.bin",       0x000000, 0x20000, 0x3fadafd6 )
  542.     ROM_LOAD( "19.bin",       0x020000, 0x20000, 0xddae9d5b )
  543.     ROM_LOAD( "20.bin",       0x040000, 0x20000, 0x08cf7a93 )
  544.     ROM_LOAD( "21.bin",       0x060000, 0x20000, 0x1ac892f5 )
  545.  
  546.     ROM_REGION( 0x100000, REGION_GFX4 | REGIONFLAG_DISPOSE )
  547.     ROM_LOAD( "gaiden.6",     0x000000, 0x20000, 0xe7ccdf9f )    /* sprites A1 */
  548.     ROM_LOAD( "gaiden.8",     0x020000, 0x20000, 0x7ef7f880 )    /* sprites B1 */
  549.     ROM_LOAD( "gaiden.10",    0x040000, 0x20000, 0xa6451dec )    /* sprites C1 */
  550.     ROM_LOAD( "gaiden.12",    0x060000, 0x20000, 0x90f1e13a )    /* sprites D1 */
  551.     ROM_LOAD( "gaiden.7",     0x080000, 0x20000, 0x016bec95 )    /* sprites A2 */
  552.     ROM_LOAD( "gaiden.9",     0x0a0000, 0x20000, 0x6e9b7fd3 )    /* sprites B2 */
  553.     ROM_LOAD( "gaiden.11",    0x0c0000, 0x20000, 0x7fbfdf5e )    /* sprites C2 */
  554.     ROM_LOAD( "gaiden.13",    0x0e0000, 0x20000, 0x7d9f5c5e )    /* sprites D2 */
  555.  
  556.     ROM_REGION( 0x20000, REGION_SOUND1 )    /* 128k for ADPCM samples - sound chip is OKIM6295 */
  557.     ROM_LOAD( "gaiden.4",     0x0000, 0x20000, 0xb0e0faf9 ) /* samples */
  558. ROM_END
  559.  
  560. ROM_START( shadoww )
  561.     ROM_REGION( 0x40000, REGION_CPU1 )    /* 2*128k for 68000 code */
  562.     ROM_LOAD_EVEN( "shadoww.1",    0x00000, 0x20000, 0xfefba387 )
  563.     ROM_LOAD_ODD ( "shadoww.2",    0x00000, 0x20000, 0x9b9d6b18 )
  564.  
  565.     ROM_REGION( 0x10000, REGION_CPU2 )    /* 64k for the audio CPU */
  566.     ROM_LOAD( "gaiden.3",     0x0000, 0x10000, 0x75fd3e6a )   /* Audio CPU is a Z80  */
  567.  
  568.     ROM_REGION( 0x010000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  569.     ROM_LOAD( "gaiden.5",     0x000000, 0x10000, 0x8d4035f7 )    /* 8x8 tiles */
  570.  
  571.     ROM_REGION( 0x080000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  572.     ROM_LOAD( "14.bin",       0x000000, 0x20000, 0x1ecfddaa )
  573.     ROM_LOAD( "15.bin",       0x020000, 0x20000, 0x1291a696 )
  574.     ROM_LOAD( "16.bin",       0x040000, 0x20000, 0x140b47ca )
  575.     ROM_LOAD( "17.bin",       0x060000, 0x20000, 0x7638cccb )
  576.  
  577.     ROM_REGION( 0x080000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  578.     ROM_LOAD( "18.bin",       0x000000, 0x20000, 0x3fadafd6 )
  579.     ROM_LOAD( "19.bin",       0x020000, 0x20000, 0xddae9d5b )
  580.     ROM_LOAD( "20.bin",       0x040000, 0x20000, 0x08cf7a93 )
  581.     ROM_LOAD( "21.bin",       0x060000, 0x20000, 0x1ac892f5 )
  582.  
  583.     ROM_REGION( 0x100000, REGION_GFX4 | REGIONFLAG_DISPOSE )
  584.     ROM_LOAD( "gaiden.6",     0x000000, 0x20000, 0xe7ccdf9f )    /* sprites A1 */
  585.     ROM_LOAD( "gaiden.8",     0x020000, 0x20000, 0x7ef7f880 )    /* sprites B1 */
  586.     ROM_LOAD( "gaiden.10",    0x040000, 0x20000, 0xa6451dec )    /* sprites C1 */
  587.     ROM_LOAD( "shadoww.12a",  0x060000, 0x10000, 0x9bb07731 )    /* sprites D1 */
  588.     ROM_LOAD( "shadoww.12b",  0x070000, 0x10000, 0xa4a950a2 )    /* sprites D1 */
  589.     ROM_LOAD( "gaiden.7",     0x080000, 0x20000, 0x016bec95 )    /* sprites A2 */
  590.     ROM_LOAD( "gaiden.9",     0x0a0000, 0x20000, 0x6e9b7fd3 )    /* sprites B2 */
  591.     ROM_LOAD( "gaiden.11",    0x0c0000, 0x20000, 0x7fbfdf5e )    /* sprites C2 */
  592.     ROM_LOAD( "shadoww.13a",  0x0e0000, 0x10000, 0x996d2fa5 )    /* sprites D2 */
  593.     ROM_LOAD( "shadoww.13b",  0x0f0000, 0x10000, 0xb8df8a34 )    /* sprites D2 */
  594.  
  595.     ROM_REGION( 0x20000, REGION_SOUND1 )    /* 128k for ADPCM samples - sound chip is OKIM6295 */
  596.     ROM_LOAD( "gaiden.4",     0x0000, 0x20000, 0xb0e0faf9 ) /* samples */
  597. ROM_END
  598.  
  599. ROM_START( ryukendn )
  600.     ROM_REGION( 0x40000, REGION_CPU1 )    /* 2*128k for 68000 code */
  601.     ROM_LOAD_EVEN( "ryukendn.1",  0x00000, 0x20000, 0x6203a5e2 )
  602.     ROM_LOAD_ODD ( "ryukendn.2",  0x00000, 0x20000, 0x9e99f522 )
  603.  
  604.     ROM_REGION( 0x10000, REGION_CPU2 )    /* 64k for the audio CPU */
  605.     ROM_LOAD( "ryukendn.3",   0x0000, 0x10000, 0x6b686b69 )   /* Audio CPU is a Z80  */
  606.  
  607.     ROM_REGION( 0x010000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  608.     ROM_LOAD( "ryukendn.5",   0x000000, 0x10000, 0x765e7baa )    /* 8x8 tiles */
  609.  
  610.     ROM_REGION( 0x080000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  611.     ROM_LOAD( "14.bin",       0x000000, 0x20000, 0x1ecfddaa )
  612.     ROM_LOAD( "15.bin",       0x020000, 0x20000, 0x1291a696 )
  613.     ROM_LOAD( "16.bin",       0x040000, 0x20000, 0x140b47ca )
  614.     ROM_LOAD( "17.bin",       0x060000, 0x20000, 0x7638cccb )
  615.  
  616.     ROM_REGION( 0x080000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  617.     ROM_LOAD( "18.bin",       0x000000, 0x20000, 0x3fadafd6 )
  618.     ROM_LOAD( "19.bin",       0x020000, 0x20000, 0xddae9d5b )
  619.     ROM_LOAD( "20.bin",       0x040000, 0x20000, 0x08cf7a93 )
  620.     ROM_LOAD( "21.bin",       0x060000, 0x20000, 0x1ac892f5 )
  621.  
  622.     ROM_REGION( 0x100000, REGION_GFX4 | REGIONFLAG_DISPOSE )
  623.     ROM_LOAD( "gaiden.6",     0x000000, 0x20000, 0xe7ccdf9f )    /* sprites A1 */
  624.     ROM_LOAD( "gaiden.8",     0x020000, 0x20000, 0x7ef7f880 )    /* sprites B1 */
  625.     ROM_LOAD( "gaiden.10",    0x040000, 0x20000, 0xa6451dec )    /* sprites C1 */
  626.     ROM_LOAD( "shadoww.12a",  0x060000, 0x10000, 0x9bb07731 )    /* sprites D1 */
  627.     ROM_LOAD( "ryukendn.12b", 0x070000, 0x10000, 0x1773628a )    /* sprites D1 */
  628.     ROM_LOAD( "gaiden.7",     0x080000, 0x20000, 0x016bec95 )    /* sprites A2 */
  629.     ROM_LOAD( "ryukendn.9a",  0x0a0000, 0x10000, 0xc821e200 )    /* sprites B2 */
  630.     ROM_LOAD( "ryukendn.9b",  0x0b0000, 0x10000, 0x6a6233b3 )    /* sprites B2 */
  631.     ROM_LOAD( "gaiden.11",    0x0c0000, 0x20000, 0x7fbfdf5e )    /* sprites C2 */
  632.     ROM_LOAD( "shadoww.13a",  0x0e0000, 0x10000, 0x996d2fa5 )    /* sprites D2 */
  633.     ROM_LOAD( "ryukendn.13b", 0x0f0000, 0x10000, 0x1f43c507 )    /* sprites D2 */
  634.  
  635.     ROM_REGION( 0x20000, REGION_SOUND1 )    /* 128k for ADPCM samples - sound chip is OKIM6295 */
  636.     ROM_LOAD( "gaiden.4",     0x0000, 0x20000, 0xb0e0faf9 ) /* samples */
  637. ROM_END
  638.  
  639. ROM_START( tknight )
  640.     ROM_REGION( 0x40000, REGION_CPU1 )    /* 2*128k for 68000 code */
  641.     ROM_LOAD_EVEN( "tkni1.bin",    0x00000, 0x20000, 0x9121daa8 )
  642.     ROM_LOAD_ODD ( "tkni2.bin",    0x00000, 0x20000, 0x6669cd87 )
  643.  
  644.     ROM_REGION( 0x10000, REGION_CPU2 )    /* 64k for the audio CPU */
  645.     ROM_LOAD( "tkni3.bin",    0x0000, 0x10000, 0x15623ec7 )   /* Audio CPU is a Z80  */
  646.  
  647.     ROM_REGION( 0x010000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  648.     ROM_LOAD( "tkni5.bin",    0x000000, 0x10000, 0x5ed15896 )    /* 8x8 tiles */
  649.  
  650.     ROM_REGION( 0x080000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  651.     ROM_LOAD( "tkni7.bin",    0x000000, 0x80000, 0x4b4d4286 )
  652.  
  653.     ROM_REGION( 0x080000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  654.     ROM_LOAD( "tkni6.bin",    0x000000, 0x80000, 0xf68fafb1 )
  655.  
  656.     ROM_REGION( 0x100000, REGION_GFX4 | REGIONFLAG_DISPOSE )
  657.     ROM_LOAD( "tkni9.bin",    0x000000, 0x80000, 0xd22f4239 )    /* sprites */
  658.     ROM_LOAD( "tkni8.bin",    0x080000, 0x80000, 0x4931b184 )    /* sprites */
  659.  
  660.     ROM_REGION( 0x20000, REGION_SOUND1 )    /* 128k for ADPCM samples - sound chip is OKIM6295 */
  661.     ROM_LOAD( "tkni4.bin",    0x0000, 0x20000, 0xa7a1dbcf ) /* samples */
  662. ROM_END
  663.  
  664. ROM_START( wildfang )
  665.     ROM_REGION( 0x40000, REGION_CPU1 )    /* 2*128k for 68000 code */
  666.     ROM_LOAD_EVEN( "1.3st",    0x00000, 0x20000, 0xab876c9b )
  667.     ROM_LOAD_ODD ( "2.5st",    0x00000, 0x20000, 0x1dc74b3b )
  668.  
  669.     ROM_REGION( 0x10000, REGION_CPU2 )    /* 64k for the audio CPU */
  670.     ROM_LOAD( "tkni3.bin",    0x0000, 0x10000, 0x15623ec7 )   /* Audio CPU is a Z80  */
  671.  
  672.     ROM_REGION( 0x010000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  673.     ROM_LOAD( "tkni5.bin",    0x000000, 0x10000, 0x5ed15896 )    /* 8x8 tiles */
  674.  
  675.     ROM_REGION( 0x080000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  676.     ROM_LOAD( "14.3a",        0x000000, 0x20000, 0x0d20c10c )
  677.     ROM_LOAD( "15.3b",        0x020000, 0x20000, 0x3f40a6b4 )
  678.     ROM_LOAD( "16.1a",        0x040000, 0x20000, 0x0f31639e )
  679.     ROM_LOAD( "17.1b",        0x060000, 0x20000, 0xf32c158e )
  680.  
  681.     ROM_REGION( 0x080000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  682.     ROM_LOAD( "tkni6.bin",    0x000000, 0x80000, 0xf68fafb1 )
  683.  
  684.     ROM_REGION( 0x100000, REGION_GFX4 | REGIONFLAG_DISPOSE )
  685.     ROM_LOAD( "tkni9.bin",    0x000000, 0x80000, 0xd22f4239 )    /* sprites */
  686.     ROM_LOAD( "tkni8.bin",    0x080000, 0x80000, 0x4931b184 )    /* sprites */
  687.  
  688.     ROM_REGION( 0x20000, REGION_SOUND1 )    /* 128k for ADPCM samples - sound chip is OKIM6295 */
  689.     ROM_LOAD( "tkni4.bin",    0x0000, 0x20000, 0xa7a1dbcf ) /* samples */
  690. ROM_END
  691.  
  692.  
  693.  
  694. GAME( 1988, gaiden,   0,       gaiden, gaiden,  0, ROT0, "Tecmo", "Ninja Gaiden (World)" )
  695. GAME( 1988, shadoww,  gaiden,  gaiden, gaiden,  0, ROT0, "Tecmo", "Shadow Warriors (US)" )
  696. GAME( 1989, ryukendn, gaiden,  gaiden, gaiden,  0, ROT0, "Tecmo", "Ninja Ryukenden (Japan)" )
  697. GAME( 1989, tknight,  0,       gaiden, tknight, 0, ROT0, "Tecmo", "Tecmo Knight" )
  698. GAME( 1989, wildfang, tknight, gaiden, tknight, 0, ROT0, "Tecmo", "Wild Fang" )
  699.